package com.qf.service.impl;

import com.qf.dao.DeveloperDao;
import com.qf.dao.ProjectDao;
import com.qf.pojo.Developer;
import com.qf.pojo.Project;
import com.qf.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName ProjectServiceImpl
 * @Description TODO
 * @Author 86181
 * @Date 2022/9/2 15:19
 * @Version 1.0
 **/
@Service("projectService")
public class ProjectServiceImpl implements ProjectService {
    @Autowired
    private ProjectDao projectDao;
    @Autowired
    private DeveloperDao developerDao;
    @Transactional
    public List<Project> findAllProject() {
        List<Project> all = projectDao.findAll();
        for (Project project : all) {
            String did = project.getDid();
            if (did!=null){
                Developer developerByDid = developerDao.findDeveloperByDid(did);
                if (developerByDid!=null){
                    project.setDeveloper(developerByDid);
                }
            }
        }
        return all;
    }

    public int delete(int pid) {
        int i = projectDao.deleteProject(pid);
        return i;
    }

    public int addProject(Project project) {
        int i = projectDao.addProject(project);
        return i;
    }
}
